package org.shoukaiseki.common.random;

import org.apache.commons.lang3.RandomUtils;

/**
 * 随机密码生成
 * org.shoukaiseki.common.random.RandomPassword
 * <br>
 *
 * @author shoukaiseki ブログ http://www.shoukaiseki.top/<br> E-メール jiang28555@Gmail.com<br>
 * @date 2020-11-30 17:01:11<br>
 */
public class RandomPassword {
    public static String randomPasswordString(){
        return new String(randomPassword());
    }

    public static char[] randomPassword(){
        //随机密码长度,6-16位
        int size = RandomUtils.nextInt(8, 17);
        char[] bytes=new char[size];
        int i=0;
        bytes[i]=(char)RandomUtils.nextInt(48,58);
        i++;
        bytes[i]= RandomChar.randomLowerCaseEnglish();
        i++;
        bytes[i]= RandomChar.randomUpperCaseEnglish();
        i++;
        bytes[i]= RandomChar.randomSymbol();
        i++;
        do{
            bytes[i]=(char)RandomUtils.nextInt(33,127);
            i++;
        }while (i<bytes.length);
        return bytes;
    }


}
